from os import listdir
from os.path import isfile, join
import pandas as pd
from pathlib import Path

file_dir = 'data/人口普查数据/'
out_dir = 'output/人口普查数据-csv/'

Path(out_dir).mkdir(parents=True, exist_ok=True)

for file in [f for f in listdir(file_dir) if isfile(join(file_dir, f))]:
    data_xls = pd.read_excel(file_dir + file, sheet_name=0, index_col=0, skiprows=None, usecols=lambda x: 'Unnamed' not in x)
    data_xls.to_csv(out_dir + file[:file.rindex('.')] + '.csv', encoding='utf-8')
